import Vue from 'vue'

import VueRouter from 'vue-router'

// 解决重复点击首页报错
const originalPush = VueRouter.prototype.push
   VueRouter.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}
Vue.use(VueRouter)
//定义路由
const routes = [
  //登录路由
  {
    path: '/',
    redirect:'/login'
  },
  {
    path: '/login',
    component: () => import("../views/login/login.vue")
  },
  //404
  {
    path:'/404',
    name:'404',
    component: ()=>import("../views/404.vue")
  },
  //404
  {
    path:'*',
    redirect:'/404',
  },
  // 整体布局的路由
  {
    path: '/index',
    redirect:'/home',
    name: 'index',
    component: () => import("../views/index.vue"),
    children: [
      //首页路由
      {
        path: '/home',
        name: 'home',
        component: () => import("../views/home/home.vue")
      },
      // 用户列表路由
      {
        path: '/userList',
        name: 'userList',
        component: () => import("../views/dataManage/userList.vue")
      },
      // 商家列表路由
      {
        path: '/shopList',
        name: 'shopList',
        component: () => import("../views/dataManage/shopList.vue")
      },
      // 食品列表路由
      {
        path: '/foodList',
        name: 'foodList',
        component: () => import("../views/dataManage/foodList.vue")
      },
      // 订单列表路由
      {
        path: '/orderList',
        name: 'orderList',
        component: () => import("../views/dataManage/orderList.vue")
      },
      // 管理员列表路由
      {
        path: '/adminList',
        name: 'adminList',
        component: () => import("../views/dataManage/adminList.vue")
      },
      // 添加商铺列表路由
      {
        path: '/addShop',
        name: 'addShop',
        component: () => import("../views/addData/addShop.vue")
      },
      // 添加商品列表路由
      {
        path: '/addGood',
        name: 'addGood',
        component: () => import("../views/addData/addGood.vue")
      },
      // 用户分布列表路由
      {
        path: '/User',
        name: 'User',
        component: () => import("../views/chart/User.vue")
      },
      // 文本编辑路由
      {
        path: '/textEdit',
        name: 'textEdit',
        component: () => import("../views/edit/textEdit.vue")
      },
      // 管理员设置路由
      {
        path: '/adminSetting',
        name: 'adminSetting',
        component: () => import("../views/setting/adminSetting.vue")
      },
      // 说明路由
      {
        path: '/explain',
        name: 'explain',
        component: () => import("../views/explain/explain.vue")
      }
    ]
  },

]

const router = new VueRouter({
  routes
})

export default router